<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>model</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .bord{
            border: 1px dashed #ee2602;
            width: 90%;
            margin: 20px auto;
        }
        .title{
            font-size: 20px;
            font-weight: bold;
            margin: 20px;
        }
        .introduce{
            font-size: 16px;
            margin: 0 0 20px 50px;
        }
        .red{
            color: red;
        }
    </style>
    <script>
        window.onload = function () {
            document.getElementById("chkAll").onclick = function () {
                var checklist = document.getElementsByName ("selected");
                if(document.getElementById("chkAll").checked)
                {
                    for(var i=0;i<checklist.length;i++)
                    {
                        checklist[i].checked = 1;
                    }
                }else{
                    for(var j=0;j<checklist.length;j++)
                    {
                        checklist[j].checked = 0;
                    }
                }
            }
        };
    </script>
</head>
<body>
<div class="bord">
    <div class="title">完成全选功能</div>
    <div class="introduce">
        已知页面代码及页面展示效果，完成全选功能<br/>
        PS : 1. 当全选按钮选中，下面列表所有都选中，否则反之。2. HTML部分不做修改
    </div>
</div>
<div class="bord">
    <div class="title">演示效果</div>
    <div class="introduce">
        <table style = 'text-align:center;width:500px;border-collapse:collapse;border:1px solid #efefef' border = 1>
            <tr>
                <th style = 'width:20%' title = '全选'>全选<input id = "chkAll" name="chkAll" type ="checkbox"/></th>
                <th style = 'width:30%'>姓名</th>
                <th style = 'width:60%'>地址</th>
            </tr>
            <tr>
                <td><input name="selected" type = "checkbox"/></td>
                <td>张三</td>
                <td><input type ="text"/></td>
            </tr>
            <tr>
                <td><input name="selected" type ="checkbox" /></td>
                <td>李四</td>
                <td><input type ="text"/></td>
            </tr>
        </table>
    </div>
</div>
<div class="bord">
    <div class="title">代码</div>
    <div class="introduce">
        <pre>
        &lt;script&gt;
            window.onload = function () {
                document.getElementById("chkAll").onclick = function () {
                    var checklist = document.getElementsByName ("selected");
                    if(document.getElementById("chkAll").checked)
                    {
                        for(var i=0;i&lt;checklist.length;i++)
                        {
                            checklist[i].checked = 1;
                        }
                    }else{
                        for(var j=0;j&lt;checklist.length;j++)
                        {
                            checklist[j].checked = 0;
                        }
                    }
                }
            };
        &lt;/script&gt;

            &lt;table style = 'text-align:center;width:500px;border-collapse:collapse;border:1px solid #efefef' border = 1&gt;
            &lt;tr&gt;
                &lt;th style = 'width:20%' title = '全选'&gt;全选&lt;input id = "chkAll" name="chkAll" type ="checkbox"/&gt;&lt;/th&gt;
                &lt;th style = 'width:30%'&gt;姓名&lt;/th&gt;
                &lt;th style = 'width:60%'&gt;地址&lt;/th&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;input name="selected" type = "checkbox"/&gt;&lt;/td&gt;
                &lt;td&gt;张三&lt;/td&gt;
                &lt;td&gt;&lt;input type ="text"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;input name="selected" type ="checkbox" /&gt;&lt;/td&gt;
                &lt;td&gt;李四&lt;/td&gt;
                &lt;td&gt;&lt;input type ="text"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
            </pre>
    </div>
</div>
</body>
</html>